package com.yswee.mallnavi.view.company;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.yswee.framework.net.ITaskContext;
import com.yswee.framework.widget.layoutview.ILayoutView;
import com.yswee.framework.widget.loading.LoadingPullToRefreshListView;
import com.yswee.mallnavi.Preference;
import com.yswee.mallnavi.activity.MainActivity;
import com.yswee.mallnavi.entity.common.CompanyEntity;
import com.yswee.mallnavi.model.BaseListModel;
import com.yswee.mallnavi.model.common.CompanyListModel;


public class ListView extends LoadingPullToRefreshListView<CompanyEntity> {

	private CompanyListModel mListModel;

	private IActionCallback mActionCallbackProxy = new IActionCallback() {
		@Override
		public void onCompanyClicked(View v, CompanyEntity company) {
			Preference.setCompany(company);
			startActivity(MainActivity.class);
		}
	};

	public ListView(Context context) {
		super(context);
	}
	
	public ListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected boolean hideContentOnAction() {
		return false;
	}

	@Override
	protected BaseListModel<CompanyEntity> createMode() {
		if (mListModel == null) {
			ITaskContext context = mContext instanceof ITaskContext ?
					(ITaskContext) mContext : null;
			mListModel = new CompanyListModel(context);
		}
		return mListModel;
	}

	@Override
	protected boolean enabledLoadNextPage() {
		return false;
	}

	@Override
	protected ILayoutView<CompanyEntity> getLayoutView(int position, CompanyEntity t, int itemViewType) {
		ListItem listitem = new ListItem(mContext);
		listitem.setActionCallback(mActionCallbackProxy);
		return listitem;
	}

	public interface IActionCallback {
		void onCompanyClicked(View v, CompanyEntity company);
	}

}
